import React, { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
// import { useTitle } from '../hooks/useTitle';

interface TitleManagerProps {
  children: React.ReactNode;
}

const TitleManager: React.FC<TitleManagerProps> = ({ children }) => {
  const location = useLocation();
  
  // 根据路由设置不同的标题
  useEffect(() => {
    const pathname = location.pathname;
    let pageTitle = '';
    
    // 根据路径设置页面标题
    switch (pathname) {
      case '/':
        pageTitle = '首页';
        break;
      case '/login':
        pageTitle = '登录';
        break;
      case '/device':
        pageTitle = '设备管理';
        break;
      case '/shebei':
        pageTitle = '设备管理';
        break;
      case '/mokuai':
        pageTitle = '模块管理';
        break;
      case '/biaoba':
        pageTitle = '报表管理';
        break;
      default:
        pageTitle = '';
        break;
    }
    
    // 设置完整标题
    const fullTitle = pageTitle 
      ? `${pageTitle} - ${import.meta.env.VITE_APP_TITLE || '日月星后台管理系统'}`
      : import.meta.env.VITE_APP_TITLE || '日月星后台管理系统';
    
    document.title = fullTitle;
  }, [location.pathname]);

  return <>{children}</>;
};

export default TitleManager; 